<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <style>
        table {
            margin-top: 50px;
            width: 80%;
            border: 1px#B3CDE8 solid;
        }

        th {
            text-align: center;
            background-color: #C8F4FF;
        }

        tr {
            height: 35px;
        }

        #top {
            margin: 50px auto;
            width: 80%;
            height: 30px;
        }

        a {
            text-decoration: none;
            color: #66F;
        }

        a:hover {
            color: #F96;
        }

        #search {
            float: right;
        }
    </style>
    <title>浏览记录</title>
</head>

<body>

    <?php

    include "isLogin.php"; //包含连接文件
    include "conn.php";
    $key = "";
   
    $key = $_POST["key"];
    $pageSize = 3; //每页显示条数
    $pageNum = empty($_GET["pageNum"]) ? 1 : $_GET["pageNum"];
    echo $key;
    mysqli_query($conn, 'set names utf8'); //告诉服务器，浏览器端字符集是utf8
    $sql = "select * from student,major where student.major_id=major.major_id "; //构造SQL语句
    //如果是提交表单
    if ($_SERVER["REQUEST_METHOD"] == "POST") {
        // $key = $_POST["key"];
        $pageNum = 1; } 
    
    
            $sql .= " and ((stu_name like '%$key%')or
            (stu_name like '%$key%') or 
            (stu_no like'%$key%') or 
            (major_name like '%$key%')or
            (date_format(birthdate, '%Y-%m-%d') like '%$key%')or
            (telephone like '%$key%')or
            (email like '%$key%')or
            (resume like '%$key%')or
            (gender like '%$key%')
            )";
    // $result = mysqli_query($conn, $sql); //获得记录集
    // $allNum = mysqli_num_rows($result); //获得记录条数
    // $endPage = ceil($allNum / $pageSize); //获得最大页号
    // $sql .= " order by stu_no limit " . ($pageNum - 1) * $pageSize . "," . $pageSize;


   

    $result = mysqli_query($conn, $sql); //获得记录集
    $allNum = mysqli_num_rows($result); //获得记录条数
    $endPage = ceil($allNum / $pageSize); //获得最大页号
    $sql .= " order by stu_no limit " . ($pageNum - 1) * $pageSize . "," . $pageSize;


    ?>
    <div id="top">
        <div id="insert">
            <a href="stuInsert.php">添加学生</a>
        </div>
        <div id="search">
            <form action="#" method="post">
                <!-- autocomplete="off" -->
                <input type="text" name="key" value="<?php echo $key ?>" />
                <input type="submit" value="查询" />
            </form>
        </div>
    </div>
    <?php
    // echo  " 查询 $sql";
    $result = mysqli_query($conn, $sql) or die("数据查询失败"); //执行SQL语句
    if (mysqli_num_rows($result) > 0) { //判断是否有查询结果
        echo "<table align='center' >"; //输出表格标签
        echo "<tr>
                <th>学号</th>
                <th>姓名</th>
                <th>性别</th>
                <th>专业</th>
                <th>生日</th>
                <th>电话</th>
                <th>电邮</th>
                <th colspan =3></th>
            </tr>"; //输出表头行
        while ($row = mysqli_fetch_assoc($result)) //从记录集获取一行数据到数组，不为false，则显示该行数据(数组中各元素
        {
    ?>
            <tr onMouseOver="this.style.backgroundColor='#D8F4FF';" onMouseOut="this.style.backgroundColor='#ffffff';">
                <?php
                echo
                "<td >$row[stu_no]</td>
            <td>$row[stu_name]</td>
            <td>$row[gender]</td>
            <td>$row[major_name]</td>
            <td>$row[birthdate]</td>
            <td>$row[telephone]</td>
            <td>$row[email]</td>        
            <td><a href='stuDail.php?stu_no=$row[stu_no]'>详情</a></td>
            <td><a href='stuupdate.php?stu_no=$row[stu_no]'>修改</a></td> 
            <td><a href=javascript:if(confirm('确定要删除吗?'))location='stuDelete.php?stu_no=$row[stu_no]'>删除</a>
            </td>"; //输出获取的一行数据"; //输出获取的一行数据
                echo "</tr>"; //输出行结束标记
               
                   }; 
            ?>
            <tr>
                <td colspan="10" align="center">
                    <a href="?pageNum=1">首页</a>
                    <a href="?pageNum=<?php echo $pageNum == 1 ? 1 : ($pageNum - 1) ?>">上一页</a>
                    <a href="?pageNum=<?php echo $pageNum == $endPage ? $endPage : ($pageNum + 1) ?>">下一页</a>
                    <a href="?pageNum=<?php echo $endPage ?>">尾页</a>
                </td>
            </tr>
        <?php
        echo "</table>"; //输出表格结束标记
    } else //没有查询结果
        echo "尚无学生信息";
        ?>

    
</body>
</html>